import { EquipControllerBase } from "./EquipControllerBase";
import { EItemUpdateOper } from "../../../Message/Game/EItemUpdateOper";
import { IView } from "../../mvc/interfaces/IView";
import { PetEquipmentModule } from "../../../modules/PetEquipmentModule";
import { WindowEvent } from "../../component/window/WindowEvent";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { DataEvent } from "../events/DataEvent";
import { ItemData } from "../resource/info/ItemData";
import { EItemUpdateType } from "../../../Message/Game/EItemUpdateType";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { EProp } from "../../../Message/Public/EProp";
import { EBind } from "../../../Message/Public/EBind";
import { ItemConfig } from "../resource/ItemConfig";
import { ItemInfo } from "../resource/info/ItemInfo";
import { PetEquipForgeConfig } from "../resource/PetEquipForgeConfig";
import { EquipmentUtil } from "../view/common/util/EquipmentUtil";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { ECategory } from "../../../Message/Public/ECategory";
import { EquipAdvanceConfig } from "../resource/EquipAdvanceConfig";
import { IPetEquipmentModule } from "../../../modules/interfaces/IPetEquipmentModule";
type int = number;
//class PetEquipController
    
    export  class PetEquipController extends EquipControllerBase
    {
        constructor()
        {
            
            super();_opertionType = EItemUpdateOper._EItemUpdatePetEquipUpgradeStar;
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._petEquipModule) 
            {
                this._petEquipModule = new PetEquipmentModule();
                this._petEquipModule.addEventListener(WindowEvent.SHOW, this.onWindowShowHandler);
                addCommonListeners(this._petEquipModule);
            }
            return this._petEquipModule;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            NetDispatcher.addCmdListener(ServerCommand.PetEquipItemInfoChange, serverBagDataChangehandler);
            Dispatcher.addEventListener(EventName.PetEquipOpenByIndex, this.onPetEquipmentWindowOpenByIndex);
            Dispatcher.addEventListener(EventName.PetEquipForge_ShowForgeModule, this.onShowPetEquipForgeModule);
            Dispatcher.addEventListener(EventName.PetBagUpdate, this.onPetBagUpdateHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdate);
            Dispatcher.addEventListener(EventName.Guide_PetEquipRefresh2, this.onGuidePetEquipRefresh);
            Dispatcher.addEventListener(EventName.Guide_PetEquipStrenthenStep2, this.onGuidePetEquipStrenthenStep2Handler);
            return;
        }

        public set currentUpdateType(arg1: int)
        {
            this._currentUpdateType = arg1;
            return;
        }

        public get currentUpdateType(): int
        {
            return this._currentUpdateType;
        }

        protected /* override */ useBindChangeHandler(arg1: DataEvent): void
        {
            cache.equipment.isUseBind_petEquip = Boolean(arg1.data);
            super.useBindChangeHandler(arg1);
            return;
        }

        /* internal  */onWindowShowHandler(arg1: WindowEvent): void
        {
            this.onGuidePetEquipRefresh();
            return;
        }

        /* internal  */onPetBagUpdateHandler(arg1: DataEvent): void
        {
            if (this._petEquipModule && !this._petEquipModule.isHide) 
            {
                this._petEquipModule.updatePetInfos();
            }
            return;
        }

        /* internal  */onRoleLevelUpdate(arg1): void
        {
            if (this._petEquipModule) 
            {
                if (cache.role.roleInfo.level >= 65) 
                {
                    this._petEquipModule.refreshOptData();
                }
            }
            return;
        }

        /* internal  */onGuidePetEquipRefresh(arg1: DataEvent=null): void
        {
            if (cache.guide.petEquipRefresh && isViewShow) 
            {
                this._petEquipModule.guidePetEquipRefresh();
            }
            return;
        }

        /* internal  */onGuidePetEquipStrenthenStep2Handler(arg1: DataEvent): void
        {
            if (cache.guide.guidePetEquipStrenthenStep == 1 && isViewShow) 
            {
                this._petEquipModule.guidePetEquipStrenthenStep2();
            }
            return;
        }

        /* internal  */onShowPetEquipForgeModule(arg1: DataEvent): void
        {
            view.show();
            return;
        }

        /* internal  */onPetEquipmentWindowOpenByIndex(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (this.view.isHide) 
            {
                view.show();
            }
            (this._petEquipModule as PetEquipmentModule).gotoPanel(loc1);
            return;
        }

        protected /* override */ autoSelectedMaterial(): void
        {
            var loc1=_opertionType;
            switch (loc1) 
            {
                case EItemUpdateOper._EItemUpdatePetEquipUpgradeStar:
                {
                    this.selectMaterialUpgradeStar();
                    break;
                }
                case EItemUpdateOper._EItemUpdatePetEquipRecast:
                {
                    this.selectMaterialRecast();
                    break;
                }
                case EItemUpdateOper._EItemUpdatePetEquipUpgradePrefix:
                {
                    this.selectMaterialUpgradePrefix();
                    break;
                }
                case EItemUpdateOper._EItemUpdatePetEquipRefresh:
                {
                    this.selectMaterialRefresh();
                    break;
                }
                case EItemUpdateOper._EItemUpdatePetEquipTransform:
                {
                    this.selectMaterialTransform();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperPetEquipStrengthen:
                {
                    this.selectMaterialStrenthen();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperPetEquipAdvance:
                {
                    this.selectMaterialAdvance();
                    break;
                }
            }
            return;
        }

        /* internal  */selectMaterialStrenthen(): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc8=null;
            if (_choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc1=[];
            var loc6=(_choosedEquipmentData[0] as ItemData).itemExInfo.strengthen;
            if (this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc6 == 11) 
            {
                MsgManager.showRollTipsMsg(Language.getString(61024));
                return;
            }
            var loc7=cache.pack.backPackCache.getPropByType(EProp._EPropEquipStrengthenProp);
            var loc9=0;
            var loc10=loc7;
            for(loc4 of loc10) 
            {
                if (!(this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc4.itemInfo.item.itemLevel == loc6 + 1 || this._currentUpdateType == EItemUpdateType._EItemUpdateRefresh && loc4.itemInfo.item.itemLevel == loc6)) 
                {
                    continue;
                }
                if (!_useBind && loc4.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc1.push({"item": loc4, "bind": loc4.itemInfo.item.bind, "level": loc4.itemInfo.item.itemLevel});
            }
            loc1.sortOn("level");
            loc1.sortOn("bind");
            if (_useBind) 
            {
                loc1.sortOn("bind", Array.DESCENDING);
            }
            loc5 = [];
            if (loc1.length > 0) 
            {
                loc5.push(loc1[0]["item"]);
            }
            if (loc5.length != 0) 
            {
                _view.update({"type":"autoChooseMaterial", "material": loc5, "isEnough": true});
            }
            else 
            {
                loc5 = [];
                loc8 = ItemConfig.instance.getPropsByType(EProp._EPropEquipStrengthenProp);
                loc2 = 0;
                while (loc2 < loc8.length) 
                {
                    loc4 = new ItemData((loc8[loc2] as ItemInfo).item.code);
                    if (this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc4.itemInfo.item.itemLevel == loc6 + 1 && loc4.itemInfo.item.bind == EBind._EBindNo || this._currentUpdateType == EItemUpdateType._EItemUpdateRefresh && loc4.itemInfo.item.itemLevel == loc6 && loc4.itemInfo.item.bind == EBind._EBindNo) 
                    {
                        loc5.push(loc4);
                    }
                    ++loc2;
                }
                _view.update({"type":"autoChooseMaterial", "material": loc5, "isEnough": false});
            }
            this.selectPropStrengthen();
            return;
        }

        /* internal  */selectPropStrengthen(): void
        {
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            if (_useLuckTuneNum == 0) 
            {
                _view.update({"type":"autoChooseLuckTune", "luckTune":[]});
                return;
            }
            var loc1=(_choosedEquipmentData[0] as ItemData).itemExInfo.strengthen;
            var loc2=cache.pack.backPackCache.getPropByType(EProp._EPropEquipStrengthenPerfectProp);
            var loc3=[];
            var loc8=0;
            var loc9=loc2;
            for(loc4 of loc9) 
            {
                if (!(this._currentUpdateType == EItemUpdateType._EItemUpdateRefresh && loc1 == loc4.itemInfo.item.itemLevel || this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc1 + 1 == loc4.itemInfo.item.itemLevel)) 
                {
                    continue;
                }
                if (!_useBind && loc4.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc3.push({"item": loc4, "bind": loc4.itemInfo.item.bind, "level": loc4.itemInfo.item.itemLevel});
            }
            loc7 = [];
            if (loc3.length > 0) 
            {
                loc3.sortOn("level");
                loc3.sortOn("bind");
                if (_useBind) 
                {
                    loc3.sortOn("bind", Array.DESCENDING);
                }
                loc7.push(loc3[0]["item"]);
                _useLuckTuneNum = 1;
                _view.update({"type":"autoChooseLuckTune", "luckTune": loc7});
            }
            else 
            {
                if (_useLuckTuneNum == 1) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(61025));
                }
                _useLuckTuneNum = 0;
                _view.update({"type":"autoChooseLuckTune", "luckTune": loc7});
            }
            return;
        }

        /* internal  */selectMaterialUpgradeStar(): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc11=0;
            var loc12=null;
            if (_choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc1=[];
            var loc6=_choosedEquipmentData[0] as ItemData;
            var loc7;
            var loc8=(loc7 = (_choosedEquipmentData[0] as ItemData).itemExInfo.p_equip_star) + 1;
            if (loc7 >= 10) 
            {
                MsgManager.showRollTipsMsg(Language.getString(61329));
                return;
            }
            var loc9=cache.pack.backPackCache.getPropByType(EProp._EPropPetInnerAlchemy);
            var loc13=0;
            var loc14=loc9;
            for(loc4 of loc14) 
            {
                if (loc4.itemInfo.item.itemLevel != loc6.itemInfo.item.itemLevel) 
                {
                    continue;
                }
                if (!_useBind && loc4.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc1.push({"item": loc4, "bind": loc4.itemInfo.item.bind, "level": loc4.itemInfo.item.itemLevel});
            }
            loc1.sortOn("level");
            loc1.sortOn("bind");
            if (_useBind) 
            {
                loc1.sortOn("bind", Array.DESCENDING);
            }
            var loc10=false;
            loc5 = [];
            if (loc1.length > 0) 
            {
                loc2 = 0;
                while (loc2 < loc1.length) 
                {
                    loc4 = loc1[loc2]["item"] as ItemData;
                    loc11 = loc11 + loc4.itemAmount;
                    loc5.push(loc4);
                    if (loc11 >= loc8) 
                    {
                        loc10 = true;
                    }
                    ++loc2;
                }
            }
            if (loc10) 
            {
                _view.update({"type":"autoChooseMaterial", "material": loc5, "amountNeed": loc8, "isEnough": true});
            }
            else 
            {
                loc5 = [];
                loc12 = ItemConfig.instance.getPropsByType(EProp._EPropPetInnerAlchemy);
                loc2 = 0;
                while (loc2 < loc12.length) 
                {
                    if ((loc4 = new ItemData((loc12[loc2] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc4.itemInfo.item.itemLevel == loc6.itemInfo.item.itemLevel) 
                    {
                        loc5.push(loc4);
                        break;
                    }
                    ++loc2;
                }
                _view.update({"type":"autoChooseMaterial", "material": loc5, "amountNeed": loc8, "isEnough": false});
            }
            return;
        }

        /* internal  */selectMaterialRecast(): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc8=null;
            var loc9=null;
            if (_choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc1=[];
            var loc5=_choosedEquipmentData[0] as ItemData;
            var loc6;
            if ((loc6 = (_choosedEquipmentData[0] as ItemData).itemExInfo.p_equip_star) < 10) 
            {
                MsgManager.showRollTipsMsg(Language.getString(61332));
                return;
            }
            var loc7=cache.pack.backPackCache.getPropByType(EProp._EPropPetEquipRecast);
            var loc10=0;
            var loc11=loc7;
            for(loc4 of loc11) 
            {
                if (loc4.itemInfo.item.itemLevel != loc5.itemInfo.item.itemLevel) 
                {
                    continue;
                }
                if (!_useBind && loc4.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc1.push({"item": loc4, "bind": loc4.itemInfo.item.bind, "level": loc4.itemInfo.item.itemLevel});
            }
            loc1.sortOn("level");
            loc1.sortOn("bind");
            if (_useBind) 
            {
                loc1.sortOn("bind", Array.DESCENDING);
            }
            if (loc1.length > 0) 
            {
                loc4 = loc1[0]["item"] as ItemData;
                _view.update({"type":"autoChooseMaterial", "material": loc4, "amountNeed": 1, "isEnough": true});
            }
            else 
            {
                loc9 = ItemConfig.instance.getPropsByType(EProp._EPropPetEquipRecast);
                loc2 = 0;
                while (loc2 < loc9.length) 
                {
                    if ((loc4 = new ItemData((loc9[loc2] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc4.itemInfo.item.itemLevel == loc5.itemInfo.item.itemLevel) 
                    {
                        loc8 = loc4;
                        break;
                    }
                    ++loc2;
                }
                _view.update({"type":"autoChooseMaterial", "material": loc8, "amountNeed": 1, "isEnough": false});
            }
            return;
        }

        /* internal  */selectMaterialUpgradePrefix(): void
        {
            var loc6=false;
            var loc7=null;
            var loc10=0;
            var loc12=null;
            var loc13=0;
            var loc14=0;
            var loc16=null;
            if (_choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc1=(_choosedEquipmentData[0] as ItemData).itemExInfo.prefix;
            var loc2=PetEquipForgeConfig.instance.getPrefixUpgateInfo(loc1);
            if (!loc2 || EquipmentUtil.isPetEquipHighestPrefix(_choosedEquipmentData[0])) 
            {
                return;
            }
            var loc3=cache.pack.backPackCache.getPropItems();
            if (_useBind) 
            {
                loc3.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc3.sortOn("bind");
            }
            var loc4=[];
            var loc5=false;
            var loc8=[];
            var loc9=false;
            if (loc2.specialMaterialCode > 0) 
            {
                loc6 = true;
                loc7 = new ItemData(loc2.specialMaterialCode);
            }
            var loc11=loc3.length;
            loc10 = 0;
            while (loc10 < loc11) 
            {
                loc12 = loc3[loc10] as ItemData;
                if (!(!_useBind && ItemsUtil.isBind(loc12))) 
                {
                    if (loc12.type != EProp._EPropPetEquipPrefix) 
                    {
                        if (loc6 && (loc12.itemCode == loc7.itemCode || loc12.itemCode == loc7.itemInfo.item.codeUnbind)) 
                        {
                            if (!loc9) 
                            {
                                loc8.push(loc12);
                                if ((loc14 = loc14 + loc12.itemAmount) >= loc2.specialMaterialNum) 
                                {
                                    loc9 = true;
                                }
                            }
                        }
                    }
                    else if (!loc5) 
                    {
                        loc4.push(loc12);
                        if ((loc13 = loc13 + loc12.itemAmount) >= loc2.amount) 
                        {
                            loc5 = true;
                        }
                    }
                }
                ++loc10;
            }
            var loc15=[];
            if (loc5) 
            {
                loc15.push({"material": loc4, "isEnough": loc5, "amountNeed": loc2.amount});
            }
            else 
            {
                loc16 = ItemConfig.instance.getPropsByType(EProp._EPropPetEquipPrefix);
                loc10 = 0;
                while (loc10 < loc16.length) 
                {
                    if ((loc12 = new ItemData((loc16[loc10] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo) 
                    {
                        loc15.push({"material":[loc12], "isEnough": loc5, "amountNeed": loc2.amount});
                    }
                    ++loc10;
                }
            }
            if (loc6) 
            {
                if (loc9) 
                {
                    loc15.push({"material": loc8, "isEnough": loc9, "amountNeed": loc2.specialMaterialNum});
                }
                else 
                {
                    loc15.push({"material":[new ItemData(loc7.itemInfo.item.codeUnbind)], "isEnough": loc9, "amountNeed": loc2.specialMaterialNum});
                }
            }
            _view.update({"type":"autoChooseMaterial", "materials": loc15});
            return;
        }

        /* internal  */selectMaterialRefresh(): void
        {
            var loc1=null;
            var loc3=0;
            var loc4=null;
            var loc7=false;
            var loc8=null;
            var loc2=[];
            var loc5=[];
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            loc1 = cache.pack.backPackCache.getPropItems();
            var loc6=[];
            loc3 = 0;
            while (loc3 < loc1.length) 
            {
                if ((loc4 = loc1[loc3] as ItemData).category == ECategory._ECategoryProp && loc4.itemInfo.item.type == EProp._EPropPetEquipRefresh && loc4.itemInfo.item.color == (_choosedEquipmentData[0] as ItemData).itemInfo.item.color) 
                {
                    if (!(!_useBind && loc4.bind == EBind._EBindYes)) 
                    {
                        loc6.push({"data": loc4, "bind": loc4.itemInfo.item.bind});
                    }
                }
                ++loc3;
            }
            if (_useBind) 
            {
                loc6.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc6.sortOn("bind");
            }
            if (loc6.length > 0) 
            {
                loc7 = true;
                loc2.push({"data": loc6[0]["data"], "isEnough": loc7, "amount": 1});
            }
            else 
            {
                loc7 = false;
                loc8 = ItemConfig.instance.getPropsByType(EProp._EPropPetEquipRefresh);
                loc3 = 0;
                while (loc3 < loc8.length) 
                {
                    if ((loc4 = new ItemData((loc8[loc3] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc4.itemInfo.item.color == (_choosedEquipmentData[0] as ItemData).itemInfo.item.color) 
                    {
                        break;
                    }
                    ++loc3;
                }
                loc2.push({"data": loc4, "isEnough": loc7, "amount": 1});
            }
            _view.update({"type":"autoChooseMaterial", "material": loc2});
            autoSelectedRecastLocks();
            return;
        }

        /* internal  */selectMaterialTransform(): void
        {
            var loc3=0;
            var loc4=0;
            var loc5=null;
            var loc7=null;
            var loc11=null;
            var loc12=null;
            if (_choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc1=[];
            var loc2=EquipAdvanceConfig.instance.getPetEquipTransMatsAmount() * _choosedEquipmentData.length;
            var loc6=cache.pack.backPackCache.getPropByType(EProp._EPropPetEquipTransform);
            var loc13=0;
            var loc14=loc6;
            for(loc5 of loc14) 
            {
                if (!_useBind && loc5.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc1.push({"item": loc5, "bind": loc5.itemInfo.item.bind, "level": loc5.itemInfo.item.itemLevel});
            }
            loc1.sortOn("level");
            loc1.sortOn("bind");
            if (_useBind) 
            {
                loc1.sortOn("bind", Array.DESCENDING);
            }
            var loc8=[];
            var loc9=false;
            var loc10=0;
            loc13 = 0;
            loc14 = loc1;
            for(loc7 of loc14) 
            {
                loc5 = loc7["item"] as ItemData;
                loc10 = loc10 + loc5.itemAmount;
                loc8.push(loc5);
                if (!(loc10 >= loc2)) 
                {
                    continue;
                }
                loc9 = true;
                break;
            }
            if (loc9) 
            {
                _view.update({"type":"autoChooseMaterial", "materials": loc8, "amountNeed": loc2, "isEnough": true});
            }
            else 
            {
                loc12 = ItemConfig.instance.getPropsByType(EProp._EPropPetEquipTransform);
                loc3 = 0;
                while (loc3 < loc12.length) 
                {
                    if ((loc5 = new ItemData((loc12[loc3] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo) 
                    {
                        loc11 = loc5;
                        break;
                    }
                    ++loc3;
                }
                _view.update({"type":"autoChooseMaterial", "materials":[loc11], "amountNeed": loc2, "isEnough": false});
            }
            return;
        }

        /* internal  */selectMaterialAdvance(): void
        {
            var loc1=null;
            var loc8=0;
            var loc9=null;
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc2=_choosedEquipmentData[0] as ItemData;
            var loc3=EquipAdvanceConfig.instance.getPetEquipAdvanceConfig(loc2.itemCode);
            if (!loc3) 
            {
                return;
            }
            var loc4=loc3.materialCode == 0 ? null : new ItemData(loc3.materialCode);
            var loc5=[];
            var loc6=[];
            var loc7=cache.pack.backPackCache.getPropItems();
            var loc10=[];
            loc8 = 0;
            while (loc8 < loc7.length) 
            {
                if ((loc9 = loc7[loc8] as ItemData).category == ECategory._ECategoryProp) 
                {
                    if (!(!_useBind && loc9.bind == EBind._EBindYes)) 
                    {
                        loc1 = {"bind": loc9.itemInfo.item.bind, "data": loc9};
                        if (loc4 && (loc9.itemCode == loc4.itemCode || loc9.itemCode == loc4.itemInfo.item.codeUnbind)) 
                        {
                            loc10.push(loc1);
                        }
                    }
                }
                ++loc8;
            }
            if (_useBind) 
            {
                loc10.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc10.sortOn("bind");
            }
            if (loc4) 
            {
                loc5.push(this.getMaterialObject(loc4, loc3.materialNum, loc10, loc6));
            }
            _view.update({"type":"autoChooseMaterial", "material": loc5, "useItems": loc6});
            return;
        }

        /* internal  */getMaterialObject(arg1: ItemData, arg2: int, arg3: Array<any>, arg4: Array<any>=null): Object
        {
            var loc1=0;
            var loc4=0;
            var loc2=false;
            var loc3;
            (loc3 = new ItemData(arg1.itemInfo.item.codeUnbind)).itemAmount = arg2;
            if (arg3.length > 0) 
            {
                loc1 = 0;
                loc4 = 0;
                while (loc4 < arg3.length) 
                {
                    loc1 = loc1 + (arg3[loc4].data as ItemData).itemAmount;
                    if (arg4) 
                    {
                        arg4.push(arg3[loc4].data);
                    }
                    if (loc1 >= arg2) 
                    {
                        loc2 = true;
                    }
                    ++loc4;
                }
            }
            if (loc2) 
            {
                (loc3 = new ItemData(arg3[0]["data"].itemCode)).itemAmount = arg2;
            }
            return {"enough": loc2, "data": loc3};
        }

        private /* var */_petEquipModule: IPetEquipmentModule;

        private /* var */_currentUpdateType: int=0;
    }
